package com.ruoyi.common.utils.sqlite;

import org.springframework.jdbc.datasource.SmartDataSource;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

public class DataSourceSqliteImpl implements SmartDataSource {

    private Connection connect;

    private String dbPath;

    public DataSourceSqliteImpl(String dbPath) {
        this.dbPath = dbPath;
    }

    @Override
    public PrintWriter getLogWriter() throws SQLException {

        return null;
    }

    @Override
    public void setLogWriter(PrintWriter out) throws SQLException {

    }

    @Override
    public void setLoginTimeout(int seconds) throws SQLException {

    }

    @Override
    public int getLoginTimeout() throws SQLException {

        return 0;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {

        return null;
    }

    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {

        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {

        return false;
    }

    @Override
    public boolean shouldClose(Connection con) {
        return false;
    }

    @Override
    public Connection getConnection() throws SQLException {
        if (connect == null) {
            connect = DriverManager.getConnection("jdbc:sqlite:" + this.dbPath);
        }
        return connect;
    }

    @Override
    public Connection getConnection(String username, String password) throws SQLException {
        return this.getConnection();
    }

}
